package com.sk.cardeal.act.home.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;

import com.sk.cardeal.R;
import com.sk.cardeal.act.home.fragment.AlreadyReachFragment;
import com.sk.cardeal.act.home.fragment.NormalVipFragment;
import com.sk.cardeal.act.home.fragment.NotExamineFragment;
import com.sk.cardeal.act.home.fragment.NotReachFragment;
import com.sk.cardeal.act.home.fragment.TemporaryFragment;
import com.sk.cardeal.act.home.fragment.ToVoidFragment;
import com.sk.cardeal.act.home.fragment.VipCustomFragment;
import com.sk.cardeal.adapter.MyPagerAdapter;
import com.sk.cardeal.base.BaseActivity;
import com.sk.cardeal.view.TitleView;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by sk on 2017/12/18.
 */

public class CustomManageActivity extends BaseActivity {

    @BindView(R.id.title_view)
    TitleView titleView;
    @BindView(R.id.my_table)
    TabLayout myTable;
    @BindView(R.id.my_pager)
    ViewPager myPager;

    VipCustomFragment vipCustomFragment;
    NormalVipFragment normalVipFragment;
    TemporaryFragment temporaryFragment;

    private List<Fragment> fragmentList = new ArrayList<>();

    @Override
    protected int getContentView() {
        return R.layout.activity_custom_manage;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        titleView.setMyCallBack(this);
        initFragments();
    }

    private void initFragments() {

        vipCustomFragment = new VipCustomFragment();
        normalVipFragment = new NormalVipFragment();
        temporaryFragment = new TemporaryFragment();

        fragmentList.add(vipCustomFragment);
        fragmentList.add(normalVipFragment);
        fragmentList.add(temporaryFragment);

        MyPagerAdapter adapter = new MyPagerAdapter(getSupportFragmentManager(), getResources().getStringArray(R.array.vip_array), fragmentList);
        myPager.setAdapter(adapter);
        myTable.setupWithViewPager(myPager);
    }

    @Override
    public void clickTitle(int i) {
        super.clickTitle(i);
        switch (i) {
            case 1:
                finish();
                break;
            case 2:
                Intent searchIntent = new Intent(mContext, SearchCustomActivity.class);
                startActivity(searchIntent);
                break;
            case 3:
                Intent intent = new Intent(mContext, NewCustomInfoActivity.class);
                startActivityForResult(intent, 10);
                break;
        }
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode == -1) {
            if (requestCode == 10) {
                vipCustomFragment.doRefresh();
                normalVipFragment.doRefresh();
                temporaryFragment.doRefresh();
            }
        }
    }
}
